<?php
/*
 * 友情链接类
 * */
class friendlink_links{
	public $G;
	public function __construct(&$G){
		$this->G = $G;
	}

	public function _init(){
		$this->dbpdo=$this->G->loadclass('dbpdo');
		$this->pages = $this->G->loadclass('pages');
	}

	public function getAll($condition=array()){
		return $this->dbpdo->query("friendlink",'*',$condition,"","inrow");
	}

	public function getAllIsView(){
		return $this->dbpdo->query("friendlink",'*',array('isview'=>1),"","inrow");
	}
	
	public function getList($Spage=1,$Snumber=PAGED,$condition="",$orderby='',$UrlStyle=""){
		$rs['data']=$this->dbpdo->query("friendlink",'*',$condition,"",$orderby,"",strval(intval($Spage-1)*$Snumber),$Snumber);
		$t=$this->dbpdo->query("friendlink",'count(*) AS total',$condition);
		$Intpages = $this->pages->set_page_info($t[0]['total'],$Snumber,$UrlStyle);
		if($rs['data']){
			$rs['pages']=$Intpages;
			$rs['total'] = $t[0]['total'];
			return $rs;
		}else{
			return false;
		}	
	}

	public function getOneLinkByID($IntID){
		return $this->dbpdo->getOne("friendlink",'*',array('id'=>$IntID));
	}

	public function save($dsw){
		return $this->dbpdo->insert_data("friendlink",$dsw);
	}

	public function update($dsw=array(),$condition=array()){
		return $this->dbpdo->update_data("friendlink",$dsw,$condition);
	}

	public function del($IntID){
		return $this->dbpdo->remove("friendlink",array("id"=>$IntID));
	}


	public function isview($IntID){
		$Strok="";
		$list=$this->dbpdo->getOne("friendlink",'*',array('id'=>$IntID));
		if($list['isview']==0){
			$row=array(
				'endtime'=>time(),
				'enduser'=>$_SESSION['tinwinsession']['uid'],
				'isview'=>1
			);
			$Strok='<span class="glyphicon glyphicon-eye-open"></span>';
		}else{
			$row=array(
				'endtime'=>time(),
				'enduser'=>$_SESSION['tinwinsession']['uid'],
				'isview'=>0
			);
			$Strok='<span class="glyphicon glyphicon-eye-close"></span>';
		}
		$this->dbpdo->update_data("friendlink",$row,array('id' => $IntID));
		return $Strok;
	}

}
?>
